package com.hm.health.Utils;

import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.ScaleAnimation;

/**
 * Created by chenshi on 2017/8/8.
 */
public class AnimationUtil {
    /**
     * 心跳动画
     *
     * @param viewHeartRate
     */
    public void playHeartBeatAnimation(final View viewHeartRate) {
        AnimationSet animationSet = new AnimationSet(true);
        animationSet.addAnimation(new ScaleAnimation(1.0f, 1.8f, 1.0f, 1.8f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f));
        animationSet.addAnimation(new AlphaAnimation(1.0f, 0.3f));
        animationSet.setDuration(500);
        animationSet.setInterpolator(new AccelerateInterpolator());
        animationSet.setFillAfter(true);
        animationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                AnimationSet animationSet1 = new AnimationSet(true);
                animationSet1.addAnimation(new ScaleAnimation(1.8f, 1.0f, 1.8f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f));
                animationSet1.addAnimation(new AlphaAnimation(0.3f, 1.0f));
                animationSet1.setDuration(1000);
                animationSet1.setInterpolator(new DecelerateInterpolator());
                animationSet1.setFillAfter(false);
                viewHeartRate.startAnimation(animationSet1);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        viewHeartRate.startAnimation(animationSet);
    }

    /**
     * 放大动画
     *
     * @param view
     */
    public void playMagnifyAnimation(final View view) {
        AnimationSet animationSet = new AnimationSet(true);
        animationSet.addAnimation(new ScaleAnimation(1.0f, 1.8f, 1.0f, 1.8f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f));
        animationSet.addAnimation(new AlphaAnimation(1.0f, 0.3f));
        animationSet.setDuration(1000);
        animationSet.setInterpolator(new AccelerateInterpolator());
        animationSet.setFillAfter(true);
        view.startAnimation(animationSet);
    }

}
